package com.easy.cloud.web.module.certification.biz.controller;

import cn.hutool.core.lang.tree.Tree;
import com.easy.cloud.web.component.core.constants.GlobalCommonConstants;
import com.easy.cloud.web.component.core.response.HttpResult;
import com.easy.cloud.web.module.certification.api.dto.DisabilityLevelDTO;
import com.easy.cloud.web.module.certification.api.vo.DisabilityLevelVO;
import com.easy.cloud.web.module.certification.biz.service.IDisabilityLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * DisabilityLevel API
 *
 * @author Fast Java
 * @date 2024-04-02 20:43:33
 */
@Slf4j
@RestController
@RequestMapping(value = "disability/level")
@Api(value = "伤残等级管理", tags = "伤残等级管理")
public class DisabilityLevelController {

    @Autowired
    private IDisabilityLevelService disabilityLevelService;

    /**
     * 新增
     *
     * @param disabilityLevelDTO 新增数据
     * @return 新增数据
     */
    @PostMapping(value = "save")
    @ApiOperation(value = "新增")
    public HttpResult<DisabilityLevelVO> save(@Validated @RequestBody DisabilityLevelDTO disabilityLevelDTO) {
        return HttpResult.ok(disabilityLevelService.save(disabilityLevelDTO));
    }

    /**
     * 更新
     *
     * @param disabilityLevelDTO 新增数据
     * @return 更新数据
     */
    @PostMapping(value = "update")
    @ApiOperation(value = "更新")
    public HttpResult<DisabilityLevelVO> update(@Validated @RequestBody DisabilityLevelDTO disabilityLevelDTO) {
        return HttpResult.ok(disabilityLevelService.update(disabilityLevelDTO));
    }

    /**
     * 根据ID移除数据
     *
     * @param disabilityLevelId ID
     * @return 是否删除成功
     */
    @GetMapping(value = "remove/{disabilityLevelId}")
    @ApiOperation(value = "根据ID移除数据")
    public HttpResult<Boolean> removeById(@PathVariable @NotNull(message = "当前ID不能为空") String disabilityLevelId) {
        return HttpResult.ok(disabilityLevelService.removeById(disabilityLevelId));
    }

    /**
     * 根据ID获取详情
     *
     * @param disabilityLevelId ID
     * @return 详情数据
     */
    @GetMapping(value = "detail/{disabilityLevelId}")
    @ApiOperation(value = "根据ID获取详情")
    public HttpResult<DisabilityLevelVO> detailById(@PathVariable @NotNull(message = "当前ID不能为空") String disabilityLevelId) {
        return HttpResult.ok(disabilityLevelService.detailById(disabilityLevelId));
    }


    /**
     * 获取残疾人等级树列表
     */
    @GetMapping(value = "tree")
    @ApiOperation(value = "获取残疾人等级树列表")
    public HttpResult<List<Tree<String>>> tree(
            @RequestParam(defaultValue = GlobalCommonConstants.DEPART_TREE_ROOT_ID) String parentId) {
        // 测试查询超管下的所有菜单
        return HttpResult.ok(disabilityLevelService.tree(parentId));
    }
}